using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using JGSY.CMS.LowCode.Platform.Infrastructure.Middleware;
using JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.ServiceModules;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.MiddlewareModules.Modules
{
    /// <summary>
    /// 日志中间件模块
    /// 包含安全日志、操作日志、审计日志等中间件
    /// </summary>
    public class LoggingMiddlewareModule : IMiddlewareModule
    {
        public string ModuleName => "日志中间件";
        public int Priority => 3;
        public bool EnableInDevelopment => true;
        public bool EnableInProduction => true;
        public bool EnableInFastMode => false; // 快速模式下减少日志中间件
        public ModulePermission RequiredPermission => ModulePermission.LoggingServices;
        public bool IsCriticalModule => true; // 关键中间件

        public void ConfigureMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 完整日志功能
            if (app.Environment.IsDevelopment())
            {
                // 开发环境启用所有日志中间件
                app.UseMiddleware<SecurityLoggingMiddleware>();
                app.UseMiddleware<OperationLoggingMiddleware>();
                app.UseMiddleware<AuditLoggingMiddleware>();
            }
            else
            {
                // 生产环境只启用安全日志
                app.UseMiddleware<SecurityLoggingMiddleware>();
            }
        }

        public void ConfigureMinimalMiddleware(WebApplication app, IConfiguration configuration)
        {
            // 精简日志功能 - 只配置安全日志
            app.UseMiddleware<SecurityLoggingMiddleware>();
        }

        public bool ValidateConfiguration(IConfiguration configuration)
        {
            // 日志中间件可以使用默认配置
            return true;
        }
    }
}
